import cfg from '../../config';
import {getView} from '../../util/api';
import {formatDate, getCurrDay, randomColor, isArrContain, isArrNoContain, findStr, backPage} from '../../util/aid';

const $ = require('../../lib/kdom');
let _view = require('raw-loader!./contacts.html');

export default class {
  path = '/train/contacts$';
  hash = '/train/contacts';
  title = '联系人';

  constructor(opt) {
    opt = opt || {};
    this.path = opt.path || this.path;
    this.hash = opt.hash || this.hash;
    this.title = opt.title || this.title;
  }

  // 输出视图
  view(cb) {
    if (!_view) {
      // 静态资源浏览器有缓存,增加时标,强制刷新!
      getView(`${cfg.train.view.contacts}?t=${(+new Date())}`, '', (rs) => {
        _view = rs;
        cb(null, _view);
      });
    } else
      cb(null, _view);
  }

  // 在已经加载的视图上操作
  bind(dv, params) {
    // backPage
    backPage('#pg-train-contacts', 'backPage', () => {
      $.router.go('/train/user', '', true);
    });
  }

  /*bind*/
}